/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.LineBorder;

public class MCellRenderer<T> implements ListCellRenderer {

    protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
    private Color normal;
    private Color focus;
    private int mode;

    public MCellRenderer(Color normal, Color focus, int mode) {
        this.normal = normal;
        this.focus = focus;
        this.mode = mode;
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index,
            boolean isSelected, boolean cellHasFocus) {
        JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
                isSelected, cellHasFocus);
            renderer.setBorder(new LineBorder(/*cellHasFocus ? focus : normal*/Color.BLACK, 1/*(list.getHeight()/5)/2-10)*/));
        if (mode == 1) {
            //list.setFixedCellHeight(300);
            //renderer.setPreferredSize(new Dimension(0, list.getSize().height/5));
            renderer.setBackground(cellHasFocus ? focus : normal);
            return renderer;
        } else {
            //list.setFixedCellHeight(list.getPreferredScrollableViewportSize().height);
            //renderer.setPreferredSize(new Dimension(0, list.getSize().height));
            renderer.setBackground(normal);
            return renderer;
        }
    }
}
